package org.sonar.plugin.deltacoverage;

import java.util.Arrays;
import java.util.List;

import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metrics;
import org.sonar.api.measures.Metric.ValueType;

public class DeltaCoverageMetrics implements Metrics {

	public final static Metric DELTA_COVERAGE = buildMetric("delta-coverage", "Delta Coverage", "Delta Coverage", Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, false, CoreMetrics.DOMAIN_TESTS);
	public final static Metric DELTA_LINE_COVERAGE = buildMetric("delta-line-coverage", "Delta Line Coverage", "Delta Line Coverage", Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, false,
			CoreMetrics.DOMAIN_TESTS);
	public final static Metric DELTA_BRANCH_COVERAGE = buildMetric("delta-branch-coverage", "Delta Branch Coverage", "Delta Branch Coverage", Metric.ValueType.PERCENT, Metric.DIRECTION_BETTER, false,
			CoreMetrics.DOMAIN_TESTS);
	public final static Metric DELTA_UNCOVERED_LINES = buildMetric("delta-uncovered-lines", "Delta Uncovered Lines", "Delta Uncovered Lines", Metric.ValueType.INT, Metric.DIRECTION_WORST, false,
			CoreMetrics.DOMAIN_TESTS);
	public final static Metric DELTA_UNCOVERED_CONDITIONS = buildMetric("delta-uncovered-conditions", "Delta Uncovered Conditions", "Delta Uncovered Conditions", Metric.ValueType.INT,
			Metric.DIRECTION_WORST, false, CoreMetrics.DOMAIN_TESTS);
	public final static Metric DELTA_LINES = buildMetric("delta-lines", "Delta Lines", "Delta Lines", Metric.ValueType.INT, Metric.DIRECTION_NONE, false, CoreMetrics.DOMAIN_TESTS);
	public final static Metric DELTA_CONDITIONS = buildMetric("delta-conditions", "Delta Conditions", "Delta Conditions", Metric.ValueType.INT, Metric.DIRECTION_NONE, false,
			CoreMetrics.DOMAIN_TESTS);

	public List<Metric> getMetrics() {
		return Arrays.asList(DELTA_COVERAGE, DELTA_LINE_COVERAGE, DELTA_BRANCH_COVERAGE, DELTA_UNCOVERED_LINES, DELTA_UNCOVERED_CONDITIONS, DELTA_LINES, DELTA_CONDITIONS);
	}

	private static Metric buildMetric(String key, String name, String description, ValueType valueType, int direction, boolean qualitative, String domain) {
		Metric.Builder builder = new Metric.Builder(key, name, valueType);
		builder.setDomain(domain);
		builder.setDescription(description);
		builder.setQualitative(qualitative);
		builder.setDirection(direction);
		return builder.create();
	}

}
